package huixue.cn.com.rxapp.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import huixue.cn.com.rxapp.util.LogUtils;

/**
 * Created by gongdongyang 2019/8/7
 * Describe:
 */
public class MyView extends View {

    Paint paint;

    int width,hieght;

    public MyView(Context context) {
        this(context,null);
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,-1);
    }

    public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.RED);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(new RectF(0,0,width,hieght),paint);
    }

    /*@Override
    public void layout(int l, int t, int r, int b) {
        super.layout(l, t, width, 400);
    }*/

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        LogUtils.e("MyView","==onMeasure==");

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        this.width = MeasureSpec.getSize(widthMeasureSpec);
        this.hieght = MeasureSpec.getSize(heightMeasureSpec);;
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        LogUtils.e("MyView","==onMeasure==");
        super.onLayout(changed, left, top, right, bottom);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        LogUtils.e("MyView","onTouchEvent==="+MotionEvent.actionToString(event.getAction()));
        return true;
    }
}
